package com.playball.lottery.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.playball.lottery.frm.yhzx.TCaiRechargeActivity;
import com.playball.lottery.frm.yhzx.WXBackActivity;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
    	api = WXAPIFactory.createWXAPI(this, TCaiRechargeActivity.APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}


	@Override
	public void onReq(BaseReq baseReq) {
		Toast.makeText(this, "运行到了这里onReq", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onResp(BaseResp baseResp) {
		Intent intent;
		int code = baseResp.errCode;
		//Toast.makeText(this, "运行到了这里onResp"+code, Toast.LENGTH_SHORT).show();

		switch (code) {
			case 0:
				intent=new Intent(this,WXBackActivity.class);
				intent.putExtra("code", 0);
				startActivity(intent);
				finish();
				break;
			case -1:
				intent=new Intent(this,WXBackActivity.class);
				intent.putExtra("code", -1);
				startActivity(intent);
				finish();
				break;
			case -2:
				intent=new Intent(this,WXBackActivity.class);
				intent.putExtra("code", -2);
				startActivity(intent);
				finish();
				break;
			default:
				break;
		}
	}
}